import {Injectable} from '@angular/core';
import {CanActivate, Router} from '@angular/router';
import {UserService} from './user.service';

@Injectable()
export class AuthGuard implements CanActivate {

  constructor(private userService: UserService, private router: Router) {
  }

  canActivate(): boolean {
    if (this.userService.isOnline()) {
      return true;
    }
    this.router.navigate(['/account/login']);
    return false;
  }
}
